﻿using D3StatsClient.Model;
using D3StatsClient.ViewModel;
using System.Windows;

namespace D3StatsClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Closing += MainWindow_Closing;

            //enable this only when making videos where you need the client window to always be ontop.
            //Do not release a version with this feature!
            //this.Topmost = true;

            MainWindowViewModel vm = new MainWindowViewModel();

            //Store in the viewmodel manager
            ViewModelManager<MainWindowViewModel>.ViewModel = vm;

            this.DataContext = vm;
        }

        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //Check if session was stopped properly before exiting
            MainWindowViewModel vm = ViewModelManager<MainWindowViewModel>.ViewModel;

            //If recording is still on, stop recording and persist data to disk.
            if (vm.IsRecording)
            {
                vm.StopRecordingSessionCommand.Execute(null);
            }
        }
    }
}
